package com.dyn.videohub.Controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dyn.videohub.Common.R;
import com.dyn.videohub.Service.AdminService;
import com.dyn.videohub.domain.Admintor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Controller
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminService adminService;

    @GetMapping("/login")
    public R<Admintor> login(@RequestParam("name") String name,@RequestParam("password") String password){
        LambdaQueryWrapper<Admintor> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Admintor::getName,name);
        Admintor admintor=adminService.getOne(lambdaQueryWrapper);
        if(admintor==null){
            return R.error("管理员不存在！");
        }
        if(!admintor.getPassword().equals(password)){
            return R.error("密码错误！");
        }
        return R.success(admintor);
    }

    @GetMapping("/hest")
    public R<String> hest(){
        String test="Hello World!";
        return R.success(test);
    }

//    @PostMapping("/getalladminitor")
//    public List<Admintor> selectAll() {
//        return adminService.list();
//    }
}

